package gsb.android;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import modele.DAO;
import org.xml.sax.SAXException;

public class MainActivity extends ListActivity
{
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Intent inter = new Intent(this, AutreActivity.class);
        inter.putExtra("Departement", l.getItemAtPosition(position).toString());
        startActivity(inter);
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageView image = (ImageView) findViewById(R.id.imageView1);
        image.setImageResource(R.drawable.gsb1);
        //lecture des noms
        List<String> lesNoms;
        try {
            lesNoms = DAO.getLesDeps();
            //Création de l'adapter
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lesNoms);
            setListAdapter(adapter);
            
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
